package controller

import (
	"fx_swift_boss/api"
	"fx_swift_boss/internal/service"
	"fx_swift_boss/pkg/code"
	"fx_swift_boss/pkg/internalerrors"
	"github.com/gin-gonic/gin"
	"net/http"
)

// 代理商详情
func GetIfcGateAgentDetails(c *gin.Context) {
	account := c.Query("agentAccount")
	result, err := service.NewIfcGateAgentSrv().GetIfcGateAgentDetails(c, account)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 代理商列表
func IfcGateAgentApplyReview(c *gin.Context) {
	req := &api.IfcGateAgentApplyReviewReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.Error())
		return
	}
	result, err := service.NewIfcGateAgentSrv().IfcGateAgentApplyReview(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 代理商资质审核列表
func IfcGateAgentApproval(c *gin.Context) {
	req := &api.IfcGateAgentApprovalReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.Error())
		return
	}
	result, err := service.NewIfcGateAgentSrv().IfcGateAgentApproval(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 资质审核操作
func OperatorIfcGateAgentReview(c *gin.Context) {
	req := &api.OperatorIfcGateAgentReviewReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.Error())
		return
	}
	err := service.NewIfcGateAgentSrv().OperatorIfcGateAgentReview(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, nil)
	}
}

// 获取boss端待审核代理商数
func GetAgentAuditNums(c *gin.Context) {
	result, err := service.NewIfcGateAgentSrv().GetAgentAuditNums(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 获取所有代理商的companyName
func GetMerChantAgentCompanyInfo(c *gin.Context) {
	result, err := service.NewIfcGateAgentSrv().GetMerChantAgentCompanyInfo(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}
